package com.gzs.learn.payment;

import com.gzs.learn.common.util.SpringContextUtil;
import com.gzs.learn.payment.config.ThreadPoolConfig;
import com.gzs.learn.payment.failover.FailoverService;
import com.gzs.learn.payment.failover.FailoverThread;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

@Component
@Slf4j
public class InitService {

    @PostConstruct
    public void initChannel() {
        // SpringContextUtil.getBean(IPaymentChannelConfigService.class).init();
    }

    @PostConstruct
    public void initFailover() {
        FailoverService service = SpringContextUtil.getBean(FailoverService.class);
        if (service == null) {
            log.warn("get FailoverService null,ignore failover service,please confirm the failover service bean");
        }
        service.initHandlers();
        ThreadPoolTaskExecutor pool = SpringContextUtil.getBean(ThreadPoolConfig.POOL_NAME_ASYNC);
        pool.submit(new FailoverThread(service));
    }
}
